<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <style>
    .voter {
      font-family: 'DejaVu Sans Mono', 'Lucida Console', 'Menlo', 'Monaco', monospace;
      font-size: 18px;
    }

    .up,
    .down {
      cursor: pointer;
      color: blue;
      font-weight: bold;
    }
  </style>
  <script src="https://cdn.polyfill.io/v1/polyfill.js?features=CustomEvent,Element.prototype.closest"></script>
  <script src="voter.js"></script>
</head>

<body>

  <div id="voter" class="voter">
    <span class="down">—</span>
    <span class="vote">0</span>
    <span class="up">+</span>
  </div>

  <script>
    var voter = new Voter({
      elem: document.getElementById('voter')
    });

    voter.setVote(5);

    document.getElementById('voter').addEventListener('change', function(e) {
      alert(e.detail);
    });
  </script>

</body>

</html>
